package com.jsgt.greekfire.ui.mine.coindetail.receipt

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.view.View
import com.fhx.core.base.BaseActivity
import com.fhx.core.utils.QRCodeUtils
import com.fhx.core.utils.ScreenUtil
import com.jsgt.greekfire.R
import com.jsgt.greekfire.WALLET_ADDRESS
import com.jsgt.greekfire.bean.AssetsBean
import kotlinx.android.synthetic.main.activity_receipt.*

/**
 * GLB/UTIT收款
 * author fhx
 * create time 2020/5/13 13:47
 **/
class ReceiptActivity : BaseActivity() {
    override fun getLayoutId(): Int = R.layout.activity_receipt

    companion object {
        const val ASSETS_BEAN = "bean"
        fun start(context: Context, bean: AssetsBean) {
            val intent = Intent(context, ReceiptActivity::class.java)
            intent.putExtra(ASSETS_BEAN, bean)
            context.startActivity(intent)
        }
    }

    override fun main() {
        val assetsBean = intent.getParcelableExtra<AssetsBean>(ASSETS_BEAN)
        title = "${assetsBean.assetName}收款"
        recharge_tv.text = WALLET_ADDRESS
        val height = ScreenUtil.dip2px(this, 200f).toInt()
        val codeBitmap = QRCodeUtils.createQRCodeBitmap(WALLET_ADDRESS, height, height)
        qr_code_iv.setImageBitmap(codeBitmap)
        copy_address_tv.visibility = View.VISIBLE
        copy_address_tv.setOnClickListener {
            //获取剪贴板管理器：
            val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            val mClipData = ClipData.newPlainText("Label", recharge_tv.text.toString())
            cm.setPrimaryClip(mClipData)
            showToast("复制成功")
        }
    }
}